<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/4/23
 * Time: 14:20
 */

namespace app\controller\index\tool;


use app\controller\index\BaseController;
use app\exception\IndexException;
use app\logic\index\font\FontLogic;
use app\logic\index\tool\ToolManageLogic;
use support\Request;
use support\Response;

class IndexController extends BaseController
{
    public $noLogin = ['getList','getDetail','getArticleModelList'];

    public function getList(Request $request):Response
    {
        $param = [];
        $data = ToolManageLogic::getInstance()->getList($param);
        return $this->endSuccess($data);
    }

    public function getDetail(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        $data = ToolManageLogic::getInstance()->getDetail($param);
        return $this->endSuccess($data);
    }

    public function collectVideoAndRemoveWatermark(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['content'] = $request->input('content');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['content'])){
            throw new IndexException(4020,'链接不存在');
        }
        $data = ToolManageLogic::getInstance()->collectVideo($param);
        return $this->endSuccess($data);
    }

    public function collectVideoAndGetWord(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['content'] = $request->input('content');
        $param['video_url'] = $request->input('video_url');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['content']) && empty($param['video_url'])){
            throw new IndexException(4020,'视频不存在');
        }
        $data = ToolManageLogic::getInstance()->collectVideoAndGetWord($param);
        return $this->endSuccess($data);
    }

    public function getArticleModelList(Request $request):Response
    {
        $param = [];
        $data = ToolManageLogic::getInstance()->getArticleModelList($param);
        return $this->endSuccess($data);
    }

    public function articleContentChange(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['model_id'] = $request->input('model_id');
        $param['content'] = $request->input('content');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['model_id'])){
            throw new IndexException(4020,'风格必选');
        }
        if(empty($param['content'])){
            throw new IndexException(4020,'内容不能为空');
        }
        $data = ToolManageLogic::getInstance()->articleContentChange($param);
        return $this->endSuccess($data);
    }

    public function articleContentPart(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['content'] = $request->input('content');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['content'])){
            throw new IndexException(4020,'内容不能为空');
        }
        $data = ToolManageLogic::getInstance()->articleContentPart($param);
        return $this->endSuccess($data);
    }

    public function getArticleGenerateLog(Request $request):Response
    {
        $param = [];
        $param['type'] = $request->input('type',1);
        $data = ToolManageLogic::getInstance()->getArticleGenerateLog($param);
        return $this->endSuccess($data);
    }

    public function articleHeadChange(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['content'] = $request->input('content');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['content'])){
            throw new IndexException(4020,'内容不能为空');
        }
        $data = ToolManageLogic::getInstance()->articleHeadChange($param);
        return $this->endSuccess($data);
    }

    public function articleKeywordGenerate(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['content'] = $request->input('content');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['content'])){
            throw new IndexException(4020,'内容不能为空');
        }
        $data = ToolManageLogic::getInstance()->articleKeywordGenerate($param);
        return $this->endSuccess($data);
    }

    public function saveToolGenerateContent(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['content'] = $request->input('content');
        $param['analyze_content'] = $request->input('analyze_content');
        $param['type'] = $request->input('type');
        $param['model_id'] = $request->input('model_id');

        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['content'])){
            throw new IndexException(4020,'内容不能为空');
        }
        if(empty($param['type'])){
            throw new IndexException(4020,'工具类型必传');
        }
        $data = ToolManageLogic::getInstance()->saveToolGenerateContent($param);
        return $this->endSuccess($data);
    }

    public function getBotImageStyleList(Request $request):Response
    {
        $param = [];
        $data = ToolManageLogic::getInstance()->getBotImageStyleList($param);
        return $this->endSuccess($data);
    }

    public function submitToolContent(Request $request):Response
    {
        $param = [];
        $param['tool_id'] = $request->input('tool_id');
        $param['content'] = $request->input('content');
        $param['model_id'] = $request->input('model_id');
        $param['tool_type'] = $request->input('tool_type');
        if(empty($param['tool_id'])){
            throw new IndexException(4020,'工具不存在');
        }
        if(empty($param['content'])){
            throw new IndexException(4020,'内容不能为空');
        }
        if(empty($param['tool_type'])){
            throw new IndexException(4020,'工具类型不能为空');
        }
        $data = ToolManageLogic::getInstance()->submitToolContent($param);
        return $this->endSuccess($data);
    }

    public function getToolAnalyzeResult(Request $request):Response
    {
        $param = [];
        $param['id'] = $request->input('id');
        $param['tool_type'] = $request->input('tool_type');
        if(empty($param['id'])){
            throw new IndexException(4020,'文章内容不存在');
        }
        if(empty($param['tool_type'])){
            throw new IndexException(4020,'工具类型不能为空');
        }

        $data = ToolManageLogic::getInstance()->getToolAnalyzeResult($param);

        return $this->endSuccess($data);
    }

}